package com.geekstudy.week9.controller;


import com.geekstudy.core.api.RpcfxRequest;
import com.geekstudy.core.api.RpcfxResolver;
import com.geekstudy.core.api.RpcfxResponse;
import com.geekstudy.core.server.RpcfxInvoker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RPCController {

    Logger logger = LoggerFactory.getLogger(RPCController.class);

    @Autowired
    RpcfxInvoker invoker;

    @PostMapping("/")
    public RpcfxResponse invoke(@RequestBody RpcfxRequest request) {
        logger.info("invoke request:{}", request);
        return invoker.invoke(request);
    }

    @Bean
    public RpcfxInvoker createInvoker(@Autowired RpcfxResolver resolver){
        return new RpcfxInvoker(resolver);
    }

    @Bean
    public RpcfxResolver createResolver(){
        return new DemoResolver();
    }

}
